package com.douqu.game.core.config.battle;

import com.douqu.game.core.config.card.CardConfig;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.util.CoreUtils;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-10-27 10:58
 */
public class MonsterConfig extends GameObject {

    public CardConfig[] cards;

    public int type;

    /**
     * 对应的怪物ID
     */
    public int[] cardParam;


    @Override
    public boolean check() {
        if(cards == null)
        {
            LogUtils.error("MonsterConfig check cards Error -> id:" + id);
            return false;
        }
        if(cardParam == null)
        {
            LogUtils.error("MonsterConfig check cardParam Error -> id:" + id);
            return false;
        }
        //配置0不走这儿的配置
        if (cards.length!= cardParam.length && cardParam[0]!=0){
            LogUtils.error("MonsterConfig check cardParam.length Error -> id:" + id);
            return false;
        }
        return super.check();
    }

    public boolean isNullCardParam()
    {
        return cardParam.length == 1 && cardParam[0] == 0;
    }

    @Override
    public boolean setVariable(String key, String value)
    {
        if("cards".equals(key))
        {
            if(CoreUtils.isErrorValue(value))
            {
                cards = new CardConfig[0];
                return true;
            }
            else
            {
                String[] strs = value.split(ConstantFactory.SEMICOLON);
                cards = new CardConfig[strs.length];
                for(int i = 0; i < strs.length; i++)
                {
                    cards[i] = DataFactory.getInstance(LoadFactory.isTestLoad()).getGameObject(DataFactory.CARD_KEY, Integer.parseInt(strs[i]));
                }
                return LoadUtils.checkNotNull(cards, this.getClass(), key, id);
            }
        }
        else if ("cardParam".equals(key)){
                cardParam = LoadUtils.loadIntArray(key, value);
                return true;
        }

        else
            return super.setVariable(key, value);
    }

}
